package com.ng.biz.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;

import com.ng.biz.model.domain.DataErrorLog;
import com.ng.biz.service.IDataErrorLog;
import com.ng.common.util.UuidUtil;

@Service
public class DataErrorLogImpl implements IDataErrorLog{

	@Override
	public void insertOrUpdateErrorLog(String taskId, String taskName, String taskType, String level, String content) {
		DataErrorLog dataErrorLog=DataErrorLog.dao.findFirst("select id,count from "+DataErrorLog.TABLE_NAME+" where task_id=? and status='0' and type=? and level=? ",taskId,taskType,level);
		if(dataErrorLog!=null) {
			dataErrorLog.setCount(dataErrorLog.getCount()+1);
			dataErrorLog.setContent(content);
			dataErrorLog.setLastTime(new Date(System.currentTimeMillis()));
			dataErrorLog.update();
		}else {
			dataErrorLog=new DataErrorLog();
			dataErrorLog.setId(UuidUtil.getUUID());
			dataErrorLog.setTaskId(taskId);
			dataErrorLog.setTitle(taskName);
			dataErrorLog.setType(taskType);
			dataErrorLog.setLevel(level);
			dataErrorLog.setContent(content);
			dataErrorLog.setStartTime(new Date(System.currentTimeMillis()));
			dataErrorLog.setStatus("0");
			dataErrorLog.setCount(1);
			dataErrorLog.save();
		}
	}

}
